package org.testis.data.parser;

import org.testis.data.*;
import org.testis.logging.AtofLogLevel;
import org.testis.logging.LogSenderService;
import org.testis.wirelesssecuritymodule.data.WirelessSecurityModuleDataObject;
import java.util.LinkedHashMap;


/**
 * Defines a class to parse data for communication module
 * @author nurhat
 */
public class WirelessSecurityModuleDop implements TestStepDop
{

    /**
     * Parsing data and creating a CommunicationModuleDataObject
     * Returns null if any required attribute not given
     * @param data
     * @return
     */
    public TestStepDataObject convert(TestStepDataObject data)
    {
        WirelessSecurityModuleDataObject dataObj =
            new WirelessSecurityModuleDataObject(data);
        LinkedHashMap<String, String> map = data.getDataToApply();
        LinkedHashMap<String, String> modulMap = data.getModuleDataToApply();
        String iFace = modulMap.get(AtofModuleParameterNames.WSM_INTERFACE);
        String wpaDriver = modulMap.get(AtofModuleParameterNames.WSM_WPADRIVER);//t_network_adaptersa ekle

        String wpaProto = map.get(AtofModuleParameterNames.WSM_WPAPROTO);
        String wpaPwd = map.get(AtofModuleParameterNames.WSM_WPAPWD);
        String wpaSsid = map.get(AtofModuleParameterNames.WSM_WPASSID);

        if (iFace == null) {
            LogSenderService.putMessageOnQueue("WirelessSecurityModuleDop",
                                               AtofLogLevel.ERROR,
                                               "WSM DataObject is not correctly " +
                                               AtofModuleParameterNames.WSM_INTERFACE +
                                               " not given.",
                                               data.getMessageId());
            return null;
        }
        dataObj.setParamInterface(iFace);
        dataObj.setWpaDriver(wpaDriver);
        dataObj.setWpaPwd(wpaPwd);
        dataObj.setWpaProto(wpaProto);
        dataObj.setWpaSsid(wpaSsid);
        return dataObj;

    }
}
